<?php include "../public/header.php";?>
<?php include "../public/header_edit.php";?>
<style>
    .shenren{display: none}
</style>

<body id="optPage">
<form class="layui-form layui-form-pane" id="commentForm">
    <div class="page-title">
        <div class="page-title-con">
            <span>回复邮件</span><div class="move_title"></div>
            <div class="page-title-opt-list">
                <button type="button" class="layui-btn layui-btn-sm btn-dark marginr5" key="0" lay-submit="" lay-filter="add" style="background: #aaa">存草稿</button>
                <button type="button" class="layui-btn layui-btn-sm btn-dark marginr5" key="1" lay-submit="" lay-filter="add">发送</button>
                <span id="page-close" class="page-close" onclick="layer_close()">×</span>
            </div>
        </div>
    </div>
    <div class="main-container">
        <div class="block-generic">


            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="edittits"><span>基本信息</span></div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>主题</label>
                        <div class="layui-input-block">
                            <input type="text" name="title" id="title" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>发送给</label>
                        <div class="layui-input-block relative">
                            <div class="tanxian">
                                <div class="tanxianclick" onclick="openPage('../public/choose_userpart.php?dom=faer&type=user&single=2','770px','490px');"></div>
                                <div class="tanxiannei" id="faer"></div>
                            </div>
                            <div class="tancheckdiv"><div class="tancheck" onclick="openPage('../public/choose_userpart.php?dom=faer&type=user&single=2','770px','490px');"><i class="layui-icon layui-icon-search"></i></div></div>
                            <div id="faer_tanerror" class="tanerrormsg"></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">抄送给</label>
                        <div class="layui-input-block relative">
                            <div class="tanxian">
                                <div class="tanxianclick" onclick="openPage('../public/choose_userpart.php?dom=chaoer&type=user&single=2','770px','490px');"></div>
                                <div class="tanxiannei" id="chaoer"></div>
                            </div>
                            <div class="tancheckdiv"><div class="tancheck" onclick="openPage('../public/choose_userpart.php?dom=chaoer&type=user&single=2','770px','490px');"><i class="layui-icon layui-icon-search"></i></div></div>
                        </div>
                    </div>
                </div>
            </div>


            <div class="layui-form-item height_auto">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label label_textarea"><text>*</text>邮件内容</label>
                        <div class="layui-input-block">
                            <textarea id="explain" name="explain" placeholder="请输入" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>
            </div>

            <?php include '../public/upinfo.php'?>
        </div>


    </div>
</form>
<script>
    var param_id = getQueryVariable('id') || 0;

    $("#commentForm").validate({
        rules: {
            title: {required: true},
            explain: {required: true},
        },
        messages:{
            title: {required: "请输入"},
            explain: {required: "请输入"},
        }
    });


    var jietype;
    layui.use(['laytp', 'form'], function() {
        var form = layui.form, layer = layui.layer;
        render_input_attr();

        facade.ajax({type: 'get', url: ask_email_reply, data:{id:param_id}}).done(function(res){
            if (res.code === 2000) {
                var data = res.data.data;

                $("#title").val(data.title);
                $("#explain").val(data.explain);

                if(data.faer_info.length > 0){
                    tan_tags_init('#faer', data.faer_info);
                }
                if(data.chaoer_info.length > 0){
                    tan_tags_init('#chaoer', data.chaoer_info);
                }

                public_upload_file_load('upload_files', res.data.files)
                render_from();
                initParseMoney();
            }
        });

        form.on('submit(add)', function(data){
            data.field.status = $(this).attr('key');
            data.field.faer = tan_tags_getvalue("#faer", 'user');
            data.field.chaoer = tan_tags_getvalue("#chaoer", 'user');


            var validRes = $("#commentForm").valid();
            if(!data.field.faer){
                $("#faer").parents('.tanxian').addClass('tanerror');
                $('#faer_tanerror').text('请选择');
                validRes = false;
            }else{
                $("#faer").parents('.tanxian').removeClass('tanerror');
                $('#faer_tanerror').text('');
            }
            if(!validRes){return false;}




            data.field.files = public_upload_file_value('upload_files');
            facade.ajax({url: ask_email_reply, data:data.field}).done(function(res){
                if (res.code === 2000) {
                    window.parent.getDeptData();
                    dataPostTimeOut();
                }
            });

            return false;
        });

    });



</script>
</body>
</html>
